package cn.usersmsg.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.usersmsg.biz.IUserBiz;
import cn.usersmsg.biz.UserBizIpml;
import cn.usersmsg.model.User;

public class UserRegister extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String username = request.getParameter("username");
		String userpwd = request.getParameter("userpwd");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		User user = new User(-1,username,userpwd,new Date(),0);
		IUserBiz iub = new UserBizIpml();
		boolean b = iub.createUser(user);
		if (b) {
			request.setAttribute("username", username);	
			out.print("<script>alert('注册成功');location.href='home.jsp';</script>");
		}else{
			out.print("<script>alert('注册失败');location.href='register.jsp';</script>");
		}
	}

}
